<?php
defined('IN_PHPCMS') or exit('No permission resources.');
if(!defined('CACHE_MODEL_PATH')) define('CACHE_MODEL_PATH',PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_model'.DIRECTORY_SEPARATOR.'caches_data'.DIRECTORY_SEPARATOR);

pc_base::load_sys_class('model', '', 0);

class reg_child_source_model extends model {
	public function __construct() {
		$this->db_config = pc_base::load_config('database');
		$this->db_setting = 'default';
		$this->table_name = 'reg_child_model_source';
		parent::__construct();
	}
	
	public function getSource($parentid){
		$tree = pc_base::load_sys_class('tree');
		$where = array();
		$where['status'] = 1;
		$where['parentid'] = 0;
		$result = $this->select($where);
		$array = array();
		foreach($result as $r) {
			$r['cname'] = L($r['cn_name']);
			$r['selected'] = $r['id'] == $parentid ? 'selected' : '';
			$array[] = $r;
		}
		$str  = "<option value='\$id' \$selected>\$spacer \$cname</option>";
		$tree->init($array);
		$select_categorys = $tree->get_tree(0, $str);
		return $select_categorys;
	}
	
	public function sourceList($siteid){
		$condition = "";
		$condition .= "status = 1 and siteid = ".$siteid." and parentid != 0";
		$result = $this->select($condition);
		$source = array();
		foreach ($result as $k=>$v){
			$source[$v['id']] = $v['cn_name'];
		}
		return $source;
	}
}
?>